package com.youmingxing.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * SharePreference工具类.
 *
 * @author JHS
 */
@SuppressLint("CommitPrefEdits")
public class SharePreferenceUtil {
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    private String name = "GLOBAL_SET";
    private Context context;

    /**
     * 类的构造方法.
     *
     * @param context
     */
    public SharePreferenceUtil(Context context) {
        this.context = context;
        sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        editor = sp.edit();
    }

    /**
     * 类的构造方法.
     *
     * @param context
     * @param name
     */
    public SharePreferenceUtil(Context context, String name) {
        sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        editor = sp.edit();
    }


    /**
     * @author JHS
     */
    public void setLastupdatetime(int type, long time) {
        editor.putLong(type + "", time);
        editor.commit();
    }


    /**
     * @return
     * @author JHS
     */
    public Long getLastupdatetime(int type) {
        long time = System.currentTimeMillis();
        return sp.getLong(type + "", time);
    }

    /**
     * @author JHS
     */
    public void setUsermark(String usermarkJson) {
        editor.putString("usermarkJson", usermarkJson);
        editor.commit();
    }


    /**
     * @return
     * @author JHS
     */
    public String getUsermark() {
        return sp.getString("usermarkJson", "");
    }


    /**
     * @author JHS
     */
    public void setHXID(String usermarkJson) {
        editor.putString("hx_id", usermarkJson);
        editor.commit();
    }

    /**
     * @return
     * @author JHS
     */
    public String getHXID() {
        return sp.getString("hx_id", "");
    }

    /**
     * @author JHS
     */
    public void setHXPWD(String hx_pwd) {
        editor.putString("hx_pwd", hx_pwd);
        editor.commit();
    }

    /**
     * @return
     * @author JHS
     */
    public String getHXPWD() {
        return sp.getString("hx_pwd", "");
    }

}